//
//  CZQHomeAboutCoachVC.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/22.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQHomeAboutCoachVC.h"
#import "CZQHomePageSectionHead.h"
#import "CZQHomeAbourTableViewCell.h"
#import "CZQHomeTimeTableViewCell.h"
#import "CZQAblutCoachHeadView.h"
#import "CZQLongViewController.h"
#import "CZQEidtResumeViewController.h"
#import "CZQHomePageChildTwoVC.h"
#import "CZQHomeStudyDetailVC.h"
#import "CZQCoachMoveDetailVC.h"
#import "CZQResumeModel.h"
@interface CZQHomeAboutCoachVC ()<UITableViewDelegate,UITableViewDataSource>
/**
 //数据源
 */
@property(nonatomic,strong)NSMutableArray *dataArr;

/**
 擅长数据
 */
@property(nonatomic,strong)NSMutableArray *longDataArrM;

@property(nonatomic,weak)CZQAblutCoachHeadView *ablutCoachHeadView;


/**
 教练简历
 */
@property(nonatomic,strong)CZQResumeModel *resumeModel;

/**
 tableView
 */
@property(nonatomic,weak)UITableView *tableView;

@end

@implementation CZQHomeAboutCoachVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"教练简介";
    
    self.navigationController.view.backgroundColor = CSBlackColor;
    
    self.resumeModel = [CZQResumeModel mj_objectWithKeyValues:self.model.GetResume];
    
    
    
    
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated
{
    NSArray *cerArr = [self.resumeModel.CertificateExp mj_JSONObject];
    
    self.resumeModel._CertificateExp = cerArr;
    
    [self.tableView reloadData];
}


#pragma mark -- 懒加载

-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        
        _dataArr = [NSMutableArray array];
        
    }
    
    return _dataArr;
}
-(NSMutableArray *)studyArrM
{
    if (!_studyArrM) {
        
        _studyArrM = [NSMutableArray array];
        
    }
    
    return _studyArrM;
}


-(NSMutableArray *)longDataArrM
{
    if (!_longDataArrM) {
        
        _longDataArrM = [NSMutableArray array];
        
    }
    
    return _longDataArrM;
}

-(UITableView *)tableView
{
    if (!_tableView) {
        
        UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        
        tableView.delegate=self;
        
        tableView.dataSource=self;
        
        tableView.backgroundColor = BackGroundColor;
        
        tableView.estimatedRowHeight = 150;
        
        [self.view addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
            
        }];
        
        //        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        //注册
        [tableView registerClass:[CZQHomeTimeTableViewCell class] forCellReuseIdentifier:@"CZQHomeTimeTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQHomeAbourTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQHomeAbourTableViewCell"];
        
        
        WS(weakSelf);
        
        CZQAblutCoachHeadView *headView = [[CZQAblutCoachHeadView alloc] init];

        [headView.iconBtn sd_setImageWithURL:[Helper imageUrlStringToChinese:self.model.Pic imageType:nil] forState:UIControlStateNormal placeholderImage:PlaceHold];
        
        [headView.classBtn setTitle:[NSString stringWithFormat:@"%@教练认证",self.model.Available]];
        
        headView.nameLable.text = self.model.RealName;
        
        headView.studyLable.text = [NSString stringWithFormat:@"学员案例%ld名",self.studyArrM.count];
        
        headView.studyCountLable.text = [NSString stringWithFormat:@"已累计帮助%ld名学员",self.studyArrM.count];
        
        //学员案例点击
        [headView.studyBtn addTarget:self action:@selector(studyExeper)];
        [headView.studyLable bk_whenTapped:^{
            [weakSelf studyExeper];
        }];
        
        //教练动态
        [headView.coachBtn addTarget:self action:@selector(coachMove)];
        [headView.coachCountLable bk_whenTapped:^{
            [weakSelf coachMove];
        }];
        
        [self.view addSubview:headView];
        
        self.ablutCoachHeadView = headView;
        [headView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(tableView);
            
            make.left.width.mas_equalTo(self.view);
        }];
        
        [headView setNeedsLayout];
        [headView layoutIfNeeded];
        
        tableView.tableHeaderView = headView;
        
        
        _tableView = tableView;
    }
    return _tableView;
}

#pragma mark - UITableViewDataSource

//行数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

//列数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.section == 0){
        
        CZQHomeAbourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQHomeAbourTableViewCell"];
         cell.longLable.text = self.resumeModel.FavTags;
         cell.titleLable.text = self.model.Memo;
         
        return cell;
    }
    else if (indexPath.section == 1){
        
        CZQHomeAbourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQHomeAbourTableViewCell"];
        cell.longTipLable.text = @"";
        cell.longLable.text = @"";
        cell.titleLable.text = self.resumeModel.FavTags;
        return cell;
    }else if (indexPath.section == 2){
        CZQHomeTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQHomeTimeTableViewCell"];
        
        
        
        
        cell.arrM = self.resumeModel._CertificateExp;
        
        return cell;
        
    }else if (indexPath.section == 3){
        
        CZQHomeAbourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQHomeAbourTableViewCell"];
        cell.titleLable.text = @"";
        for (int i = 0; i < self.model.GetCoursePlan.count ; i ++) {
            
            if (i == 0) {
                cell.titleLable.text = [self.model.GetCoursePlan[i] objectForKey:@"CourseID"];
            }else
            {
                cell.titleLable.text = [NSString stringWithFormat:@"%@,%@",cell.titleLable.text,[self.model.GetCoursePlan[i] objectForKey:@"CourseID"]];
            }
            
        }
        
        
        cell.longTipLable.text = @"";
        cell.longLable.text = @"";
        return cell;
    }
    UITableViewCell *cell;
    
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    return cell  ;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc]initWithFrame:CGRectZero];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    WS(weakSelf);
    
    CZQHomePageSectionHead *sectionHead = [CZQHomePageSectionHead new];
    
    [sectionHead.moreBtn bk_removeAllBlockObservers];
    
    if (section == 0) {
        
        //简介
        sectionHead.titleLabe.text = @"简介";
        sectionHead.howLabe.text = @"";
        
    }else if (section == 1)
    {
        //擅长
        sectionHead.titleLabe.text = @"擅长";
        sectionHead.howLabe.text = @"";
        
        [sectionHead.moreBtn bk_addEventHandler:^(id sender) {
            
            
            CZQLongViewController *longVC = [CZQLongViewController new];
            
            longVC.resumeModel = weakSelf.resumeModel;
            
            [weakSelf.navigationController pushViewController:longVC animated:YES];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
    }
    else if (section == 2)
    {
        
        //证书
        
        sectionHead.titleLabe.text = [NSString stringWithFormat:@"拥有%ld项专业认证",self.resumeModel._CertificateExp.count];
        sectionHead.howLabe.text = @"";
        
        [sectionHead.moreBtn bk_addEventHandler:^(id sender) {
            
            
            CZQEidtResumeViewController*cer = [CZQEidtResumeViewController new];
            
            cer.section = 5;
            
            cer.resumeModel = weakSelf.resumeModel;
            
            cer.title = @"我的证书";
            
            [weakSelf.navigationController pushViewController:cer animated:YES];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
    }
    else if (section == 3)
    {
        
        sectionHead.titleLabe.text = @"所授课程";
        
        sectionHead.howLabe.text = [NSString stringWithFormat:@"·%ld种",self.model.GetCoursePlan.count];
        
        [sectionHead.moreBtn bk_addEventHandler:^(id sender) {
            
            //课程
            CZQHomePageChildTwoVC *courseVC = [CZQHomePageChildTwoVC new];
            
            
            
            [weakSelf.navigationController pushViewController:courseVC animated:YES];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    
    [sectionHead.moreBtn setTitle:@"编辑"];
    
    return sectionHead;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当离开某行时，让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}


#pragma mark - //学员案例点击
-(void)studyExeper
{
    if (self.studyArrM.count > 0) {
        
        CZQHomeStudyDetailVC *studyD = [CZQHomeStudyDetailVC new];
        
        studyD.studyArrM = self.studyArrM;
        
        [self.navigationController pushViewController:studyD animated:YES];
    }
    
    
}
#pragma mark -教练动态
-(void)coachMove
{
    
    CZQCoachMoveDetailVC *detal = [CZQCoachMoveDetailVC new];
    
    
    
    [self.navigationController pushViewController:detal animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
